package com.chase.framerwork.bean;

import java.util.List;

import com.chase.framerwork.bean.enums.OrderType;
import com.chase.framerwork.common.Globle;

/**
 * 分页Bean
 * 
 * @author Chase
 * 
 */
public class Pager
{

	/**
	 * 当前页
	 */
	private int pageNumber = 1;

	/**
	 * 每页记录数
	 */
	private int pageSize = 20;

	/**
	 * 查找字段
	 */
	private String searchBy;

	/**
	 * 查找关键字
	 */
	private String keyword;

	/**
	 * 排序字段
	 */
	private String orderBy;

	/**
	 * 排序类型
	 */
	private OrderType orderType;// 排序方式

	/**
	 * 总记录数
	 */
	private int totalCount;

	/**
	 * 返回结果集
	 */
	private List<?> result;

	/**
	 * 获取总页数
	 * 
	 * @return
	 */
	public int getPageCount()
	{
		int pageCount = totalCount / pageSize;
		if (totalCount % pageSize > 0)
		{
			pageCount++;
		}
		return pageCount;
	}

	public int getPageNumber()
	{
		return pageNumber;
	}

	public void setPageNumber(int pageNumber)
	{
		// 如果当前页小于第一页，则默认第一页
		if (pageNumber < 1)
		{
			pageNumber = 1;
		}

		this.pageNumber = pageNumber;
	}

	public int getPageSize()
	{
		return pageSize;
	}

	public void setPageSize(int pageSize)
	{
		if (pageSize < 1)
		{
			pageSize = 1;
		}
		else if (pageSize > Globle.MAX_PAGE_SIZE)
		{
			pageSize = Globle.MAX_PAGE_SIZE;
		}
		this.pageSize = pageSize;
	}

	public String getSearchBy()
	{
		return searchBy;
	}

	public void setSearchBy(String searchBy)
	{
		this.searchBy = searchBy;
	}

	public String getKeyword()
	{
		return keyword;
	}

	public void setKeyword(String keyword)
	{
		this.keyword = keyword;
	}

	public String getOrderBy()
	{
		return orderBy;
	}

	public void setOrderBy(String orderBy)
	{
		this.orderBy = orderBy;
	}

	public OrderType getOrderType()
	{
		return orderType;
	}

	public void setOrderType(OrderType orderType)
	{
		this.orderType = orderType;
	}

	public int getTotalCount()
	{
		return totalCount;
	}

	public void setTotalCount(int totalCount)
	{
		this.totalCount = totalCount;
	}

	public List<?> getResult()
	{
		return result;
	}

	public void setResult(List<?> result)
	{
		this.result = result;
	}

}